<?php

class Admin extends CI_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->model('admin_model');
	}

	public function index()
	{
		echo "数量：=";
		$data = $this->admin_model->select_all();
		echo $this->admin_model->get_conunt();
	}

	// 查询所有
	public function get_select_all()
	{
		$data = $this->admin_model->select_all();
		echo "获取所有信息" . PHP_EOL;
		print_r($data);
	}

	// 用查询条件查询
	public function get_select_from1()
	{
		$cont = [
			"where" => [
				'id' => 2
			]
		];
		$data = $this->admin_model->select_form($cont);
		echo "获取所有信息" . PHP_EOL;
		print_r($data);
	}

	// 用查询条件查询
	public function get_select_from2()
	{
		echo "获取所有信息v2.5" . PHP_EOL;
		$cont = [
			"order_by" => [
				'id' => 'DESC'
			]
		];
		$data = $this->admin_model->select_form($cont);

		print_r($data);
	}

	// 插入多条数据
	public function insert()
	{
		echo "获取所有信息v2.6" . PHP_EOL;
		$cont = [
			"table" => 'classification', //表明
			//插入数据内容
			'data' => [
				['id' => 10, 'name' => '栏目1'],
				['id' => 11, 'name' => '栏目2']
			]
		];
		$data = $this->admin_model->insert_batch($cont);
		print_r($data);
	}

	//插入一条数据
	public function insert_one()
	{
		echo "获取所有信息v2.8" . PHP_EOL;
		$cont = [
			"table" => 'classification', //表明
			//插入数据内容
			'data' => ['id' => 10, 'name' => '栏目1']
		];
		$data = $this->admin_model->insert_one($cont);
		print_r($data);
	}


	//更新一条数据1
	public function replace()
	{
		echo "更新信息v2.9" . PHP_EOL;
		$cont = [
			'table' => 'classification',
			// data 默认第一条是主键
			'data' => [
				'id' => 10,
				'name' => '默认第一条'
			]
		];
		$data = $this->admin_model->replace($cont);
		print_r($data);
	}

	//更新一条数据2
	public function update()
	{
		echo "更新信息v3.0.3" . PHP_EOL;
		$cont = array(
			'table' => 'classification',
			'where' => [
				'id' => 10
			],
			'data' => [
				'name' => '修改名称'
			]
		);
		$data = $this->admin_model->update($cont);
		print_r($data);
	}

	public function update_batch()
	{
		echo "更新2信息v3.0.3" . PHP_EOL;
		$cont = [
			'table' => 'classification',
			'data' => [
				['id' => 10, 'name' => '修改名称1'],
				['id' => 11, 'name' => '修改名称2']
			],
			'where' => 'id' //where 更新时要判断的键值对
		];
		$data = $this->admin_model->update_batch($cont);
		print_r($data);
	}

	public function delete1()
	{
		$cont = [
			'table' => 'classification',
			'where' => [
				'id' => 10
			]
		];
		$data = $this->admin_model->delete($cont);
		print_r($data);
	}

	public function delete2()
	{
		echo "delete2信息v3.0.9" . PHP_EOL;
		$cont = [
			'table' => ['classification', 'teacher'],
			'where' => [
				'id' => 10
			],
			'or_where' => [
				['id' => 11], ['id' => 12], ['id' => 13]
			]
		];
		$data = $this->admin_model->delete($cont);
		print_r($data);
	}

	public function delete3()
	{
		echo "delete3信息v3" . PHP_EOL;
		$cont = [
			'table' => 'teacher'
		];
		$data = $this->admin_model->delete_empty_table($cont);
		print_r($data);
	}

}
